package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.OrganizationService;
import com.yixun.qfbao.apidto.GetParentDeptReqDto;
import com.yixun.qfbao.apidto.GetParentDeptResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.GetParentDeptReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GetParentDeptHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetParentDeptHander.class);
    @Autowired
    private OrganizationService organizationService;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<GetParentDeptResDto> res = new BaseResponseDTO<>();
        GetParentDeptReqVo reqVo = (GetParentDeptReqVo)reqDto;
        GetParentDeptReqDto getOptAuthReqDto = reqVo.getParams();
        GetParentDeptResDto resDto = new GetParentDeptResDto();
        try {
              resDto = organizationService.getParentDeptBySubDept(getOptAuthReqDto);
              res.setResult(ResultEnum.SUCCESS.getNo());
              res.setResData(resDto);

        } catch (Exception e) {
            logger.error("GetParentDeptHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("获取部门信息失败");
        }
        return res;
    }
}
